VTPM_Tools: Fix error when closing only vtpm, and fix restore bug when
authorkaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk>
Fri, 3 Mar 2006 09:46:06 +0000 (10:46 +0100)
committerkaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk>
Fri, 3 Mar 2006 09:46:06 +0000 (10:46 +0100)
no dmis exist

The first bug prevented the TPM tests from running successfully more
than once in a row.

Signed-off-by: Vinnie Scarlata <vincent.r.scarlata@intel.com>
tools/vtpm_manager/manager/dmictl.c
tools/vtpm_manager/manager/securestorage.c
tools/vtpm_manager/manager/vtpm_manager.c
tools/vtpm_manager/manager/vtpmpriv.h

index 17625bc633e577333d1199fac79b8d8980ed80bb..ffbd5cd7f2a8f5c5e4dd40d007a9e437d358ac65 100644 (file)
@@ -74,7 +74,13 @@ TPM_RESULT close_dmi( VTPM_DMI_RESOURCE *dmi_res) {
          
   close(dmi_res->guest_tx_fh); dmi_res->guest_tx_fh = -1;
   close(dmi_res->vtpm_tx_fh);  dmi_res->vtpm_tx_fh = -1; 
-               
+  vtpm_globals->connected_dmis--;
+
+  if (vtpm_globals->connected_dmis == 0) {
+    // No more DMI's connected. Close fifo to prevent a broken pipe.
+    close(vtpm_globals->guest_rx_fh);
+    vtpm_globals->guest_rx_fh = -1;
+  }
  #ifndef MANUAL_DM_LAUNCH
   if (dmi_res->dmi_id != VTPM_CTL_DM) {
     if (dmi_res->dmi_pid != 0) {
@@ -118,6 +124,7 @@ TPM_RESULT VTPM_Handle_New_DMI( const buffer_t *param_buf) {
     status = TPM_BAD_PARAMETER;
     goto abort_egress;
   } else {
+    vtpm_globals->connected_dmis++; // Put this here so we don't count Dom0
     BSG_UnpackList( param_buf->bytes, 3,
                    BSG_TYPE_BYTE, &type,
                    BSG_TYPE_UINT32, &domain_id,
index 4df8531c40c95c39990392fc74afb7ef033c94e8..1c4bd4931edabd679ba7ac1e34818e43ea2cc3a6 100644 (file)
@@ -307,8 +307,8 @@ TPM_RESULT VTPM_SaveService(void) {
   TPM_RESULT status=TPM_SUCCESS;
   int fh, dmis=-1;
 
-  BYTE *flat_boot_key, *flat_dmis, *flat_enc;
-  buffer_t clear_flat_global, enc_flat_global;
+  BYTE *flat_boot_key=NULL, *flat_dmis=NULL, *flat_enc=NULL;
+  buffer_t clear_flat_global=NULL_BUF, enc_flat_global=NULL_BUF;
   UINT32 storageKeySize = buffer_len(&vtpm_globals->storageKeyWrap);
   UINT32 bootKeySize = buffer_len(&vtpm_globals->bootKeyWrap);
   struct pack_buf_t storage_key_pack = {storageKeySize, vtpm_globals->storageKeyWrap.bytes};
@@ -328,12 +328,9 @@ TPM_RESULT VTPM_SaveService(void) {
                                               sizeof(UINT32) +// storagekeysize
                                               storageKeySize, NULL) ); // storage key
 
-  flat_dmis_size = (hashtable_count(vtpm_globals->dmi_map) - 1) * // num DMIS (-1 for Dom0)
-                   (sizeof(UINT32) + 2*sizeof(TPM_DIGEST)); // Per DMI info
 
   flat_boot_key = (BYTE *) malloc( boot_key_size );
   flat_enc = (BYTE *) malloc( sizeof(UINT32) );
-  flat_dmis = (BYTE *) malloc( flat_dmis_size );
 
   boot_key_size = BSG_PackList(flat_boot_key, 1,
                                BSG_TPM_SIZE32_DATA, &boot_key_pack);
@@ -349,9 +346,13 @@ TPM_RESULT VTPM_SaveService(void) {
 
   BSG_PackConst(buffer_len(&enc_flat_global), 4, flat_enc);
 
-  // Per DMI values to be saved
+  // Per DMI values to be saved (if any exit)
   if (hashtable_count(vtpm_globals->dmi_map) > 0) {
 
+    flat_dmis_size = (hashtable_count(vtpm_globals->dmi_map) - 1) * // num DMIS (-1 for Dom0)
+                     (sizeof(UINT32) + 2*sizeof(TPM_DIGEST)); // Per DMI info
+    flat_dmis = (BYTE *) malloc( flat_dmis_size );
+
     dmi_itr = hashtable_iterator(vtpm_globals->dmi_map);
     do {
       dmi_res = (VTPM_DMI_RESOURCE *) hashtable_iterator_value(dmi_itr);
index ab391a6ccc966ccb12a09b22e0a95d13bee6120a..e9061aabed360371c149bf99747a88841a97f123 100644 (file)
@@ -754,6 +754,7 @@ TPM_RESULT VTPM_Init_Service() {
 #ifndef VTPM_MULTI_VM
   vtpm_globals->vtpm_rx_fh = -1;
   vtpm_globals->guest_rx_fh = -1;
+  vtpm_globals->connected_dmis = 0;
 #endif
   if ((vtpm_globals->dmi_map = create_hashtable(10, hashfunc32, equals32)) == NULL){
     status = TPM_FAIL;
index 845cf011ddfb8446c6e4fb1b2970e433e7b85e55..c579d50518bef4bf678cb3cffc05288642efa9c7 100644 (file)
@@ -98,6 +98,7 @@ typedef struct tdVTPM_GLOBALS {
 #ifndef VTPM_MULTI_VM
   int                 vtpm_rx_fh;
   int                 guest_rx_fh;
+  int                 connected_dmis;     // Used to close guest_rx when no dmis are connected
   
   pid_t               master_pid;
 #endif